/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.service;

import br.com.foxline.clinicplus.entity.Cbo;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
public class CboService extends GenericService<Cbo>{

    public CboService() {
        super(Cbo.class);
    }
    
     public List<Cbo> findCBO(Cbo pro) {
        String sql = "select c from Cbo c WHERE ";

        if ((!pro.getCod().equals("")) && (pro.getCod() != null)) {
            sql += " lower(c.cod) like lower(:cod) and  ";
        }

        if ((!pro.getDescr().equals("")) && (pro.getDescr() != null)) {
            sql += " lower(c.descr) like lower(:desc) and  ";
        }
        
        sql += "1=1";

        Query query = getEntityManager().createQuery(sql);

        if ((!pro.getCod().equals("")) && (pro.getCod() != null)) {
            query.setParameter("cod", pro.getCod());
        }
//        if ((!op.getNumReg().equals("")) && (op.getNumReg() != null)) {
//            query.setParameter("num", "%" + op.getNumReg() + "%");
//        }
        if ((!pro.getDescr().equals("")) && (pro.getDescr() != null)) {
            query.setParameter("desc", "%" + pro.getDescr() + "%");
        }
        return query.getResultList();

    }
    
    
}
